﻿CREATE PROCEDURE [dbo].[ListTimeEntriesByUsers]
@UserIDList NVARCHAR (255), @StartDate DATETIME, @EndDate DATETIME
AS
DECLARE 
	@sSqlString nvarchar(512)

SET
	@sSqlString = 'SELECT EntryLogID, Description, Duration, OvernightStay, EntryDate, ProjectID, UserID, CategoryID'
	
SET
	@sSqlString = @sSqlString + ' FROM EntryLog WHERE UserID IN (' + @UserIDList + ')'

SET	
	@sSqlString = @sSqlString + ' and EntryDate >= '+ CAST(@StartDate AS nvarchar(24)) + ' and EntryDate <=  ' + CAST(@EndDate AS nvarchar(24))

SET
	@sSqlString = @sSqlString + ' GROUP BY UserID'

EXEC sp_executesql @sSqlString

